package io.github.codelifeleno.jdbrelease.config;

import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.StringJoiner;

/**
 * 对应配置文件 JDBReleaseConfig.xml
 */
public class JDBReleaseConfig {

    /**
     * 对数据库的配置
     */
    private DBConfig dbConfig;
    /**
     * 数据脚本的平配置
     */
    private FileConfig fileConfig = new FileConfig();

    private String logsDirPath;
    /**
     * 要扫描的文件路径清单
     */
    private List<String> fileDirPaths = new ArrayList<>(List.of("classpath:dbConfig/changelog"));


    public DBConfig getDb() {
        return dbConfig;
    }

    public void setDb(DBConfig dbConfig) {
        this.dbConfig = dbConfig;
    }

    public FileConfig getFileConfig() {
        return fileConfig;
    }

    public void setFileConfig(FileConfig fileConfig) {
        this.fileConfig = fileConfig;
    }

    public List<String> getFileDirPaths() {
        return fileDirPaths;
    }

    public void setFileDirPaths(List<String> fileDirPaths) {
        this.fileDirPaths = fileDirPaths;
    }

    @Override
    public String toString() {
        return new StringJoiner(", ", JDBReleaseConfig.class.getSimpleName() + "[", "]")
                .add("dbConfig=" + dbConfig)
                .add("fileConfig=" + fileConfig)
                .add("logsDirPath='" + logsDirPath + "'")
                .add("fileDirPaths=" + fileDirPaths)
                .toString();
    }

    @Override
    public boolean equals(Object o) {
        if (o == null || getClass() != o.getClass()) return false;

        JDBReleaseConfig that = (JDBReleaseConfig) o;
        return Objects.equals(getDbConfig(), that.getDbConfig()) && Objects.equals(getFileConfig(), that.getFileConfig()) && Objects.equals(getLogsDirPath(), that.getLogsDirPath()) && Objects.equals(getFileDirPaths(), that.getFileDirPaths());
    }

    @Override
    public int hashCode() {
        int result = Objects.hashCode(getDbConfig());
        result = 31 * result + Objects.hashCode(getFileConfig());
        result = 31 * result + Objects.hashCode(getLogsDirPath());
        result = 31 * result + Objects.hashCode(getFileDirPaths());
        return result;
    }

    public DBConfig getDbConfig() {
        return dbConfig;
    }

    public void setDbConfig(DBConfig dbConfig) {
        this.dbConfig = dbConfig;
    }

    public JDBReleaseConfig(DBConfig dbConfig, FileConfig fileConfig, String logsDirPath, List<String> fileDirPaths) {
        setDbConfig(dbConfig);
        setFileConfig(fileConfig);
        setLogsDirPath(logsDirPath);
        setFileDirPaths(fileDirPaths);
    }

    public JDBReleaseConfig(DBConfig dbConfig) {
        setDbConfig(dbConfig);
    }

    public String getLogsDirPath() {
        return logsDirPath;
    }

    public void setLogsDirPath(String logsDirPath) {
        this.logsDirPath = logsDirPath;
    }
}
